package the_tenth_chapter;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 功能：创建目录e:\abc，并创建一个文件a.txt，并向给文件中写入字符串"Welcome"5次
 * @author explorati
 *
 */
public class FileTest {

	public static void main(String[] args) {
		//生成文件夹
		File file1 = new File("C:/Users/Administrator/Desktop/");
		file1.mkdir();
		//新建一个文件abc.txt
		File file2 = new File(file1, "abc.txt");
		//文件输出流
		FileOutputStream out1;
		try {
			//向文件file2即abc.txt中输出
			out1 = new FileOutputStream(file2);
			String s = "Welcome";
			byte[] b = s.getBytes();
			for (int i = 0; i < 5; i++) {
				try {
					//将数组b中从0开始到b.length的数据输出到流中
					out1.write(b, 0, b.length);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		}

	}
}
